package com.xyu.controller;
import com.xyu.po.FormData2;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class FormController {
    private final Map<String, String> userStore = new HashMap<>();
    public FormController() {
        // 初始化用户存储，模拟数据库中的用户数据
        userStore.put("admin", "123456");
        userStore.put("user", "123456");
    }
    @PostMapping("/submitForm")
    public ResponseEntity<String> submitForm(@RequestBody FormData2 formData) {
        // 从请求中获取用户名和密码
        String name = formData.getName();
        System.out.println(name);
        String password = formData.getEmail(); // 使用 email 字段来传递密码、
        System.out.println(password);
        // 验证用户名和密码
        if (userStore.containsKey(name) && userStore.get(name).equals(password)) {
            System.out.println("登录成功!");
            return ResponseEntity.ok("Login successful");
        } else {
            return ResponseEntity.status(401).body("Invalid credentials");
        }
    }

};
